/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.cashmate.struts;

import com.cashmate.hibernate.pojo.Employees;
import com.opensymphony.xwork2.ActionSupport;
import org.apache.log4j.Logger;
import org.apache.struts2.ServletActionContext;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Result;

/**
 *
 * @author dean
 * for use with <s:action>
 */
@Result(name = "success", type = "redirect", location = "${url}")
public class GlobalRedirect extends ActionSupport {
    
    private final Logger logger = Logger.getLogger(GlobalRedirect.class);
    private String url;
    private final Employees emps = (Employees) ServletActionContext.getRequest().getSession().getAttribute("employee");

    public String getUrl() {
        return url;
    }

    public void setUrl(String url) {
        this.url = url;
    }
    
    @Action(value="/redirect-page")
    @Override
    public String execute() throws Exception {
        try {
            logger.info(emps.getIdnumber() +" "+emps.getCompletename()+" "+emps.getBranchname()+" has been redirected to "+url);
        } catch (Exception e) {
            logger.fatal(e.getMessage(),e);
            throw e;
        }
        return SUCCESS;
    }
}
